package com.skit.main.adapter

import android.app.Application
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.skit.main.R
import com.youth.banner.Banner
import com.youth.banner.indicator.CircleIndicator

/**
 * @author shuike [Contact me.](mailto:shuike007@gmail.com)
 * @version 1.0
 * @since 2020/5/19
 */
class MainRecyclerViewBannerAdapter(private val list: MutableList<String>) :
    RecyclerView.Adapter<MainRecyclerViewBannerAdapter.ViewHolder>() {
    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val banner: Banner<String, MainBannerAdapter> =
            itemView.findViewById(R.id.banner)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflate =
            LayoutInflater.from(parent.context).inflate(R.layout.main_re_item_banner, parent, false)
        return ViewHolder(
            inflate
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.banner.adapter = MainBannerAdapter(list)
        holder.banner.indicator = CircleIndicator(holder.banner.context)
    }

    override fun getItemCount(): Int = if (list.size > 0) 1 else 0
}